Introduction
AIH-Search utilizes OpenSearch engine. This means that queries are running in OpenSearch cluster and have the same structure as they have in OpenSearch (OpenSearch documentation).
Building the Query
#
Core query objectThe Query JSON has the following structure:
{ "query": QUERY_CLAUSE_HERE}
An empty search (i.e. {"query": {}}
) is equivalent to a match_all query, which, as the name suggests, matches all documents.
See query clauses Query Clauses documentation.
#
bool clauseAll queries use the boolean query clause to combine each query clause. The base structure of the query will then always be the following:
{ "query": { "bool": { } }}
#
Operator to query-clause locationThe two sub-clauses must_not and filter are used for the query-clauses. See the mapping table below, for where a query clause should be placed, based on the operator:
Equals | Not Equals | GT / GTE / LT / LTE | Contains | Not Contains | Null | Not null | Exists | Not exists | |
---|---|---|---|---|---|---|---|---|---|
must_not | x | x | x | x | |||||
filter | x | x | x | x | x |
#
"Exists / Not Exists" with no sub-queriesIf the user does not provide any query clauses beneath an "Exists / Not Exists" row, then it must be understood as an "Any content / No content" query ("Exists / Not Exists" is only used on lists).
The bool part of the nested query should be replaced by the "match_all" : {} query.
#
ExamplesField | Operator | Value |
---|---|---|
PopulationItems | Not Exists |
{ "query": { "bool": { "must_not": [ { "nested": { "path": "PopulationItems", "query": { "match_all": {} <-- This is where the "bool" would normally be placed } } } ] } }}
#
Simple QueryEx. User has the following two rows in their query:
Field | Operator | Value |
---|---|---|
FailureMode | Not Equals | "Micro Pitting" |
StartDate | > | 13.01.2021 |
That would translate to the following query, where row 1 is in the must_not sub-clause and row 2 is in the filter sub-clause:
{ "query": { "bool": { "must_not": [ { "terms": { "FailureMode": [ "Micro Pitting" ] } } ], "filter": [ { "range": { "startDate": { "gt": "13.01.2021" } } } ] } }}
#
Null operatorThe null / not null operators are used to determine whether a field has been assigned a value.
Ex., the user wishes to find all deviations that have not been assigned a failure mode:
Field | Operator | Value |
---|---|---|
FailureMode | Null |
That would translate to the following query:
{ "query": { "bool": { "must_not": [ { "exists": { "field": "failureMode" } } ] } }}